from   myapp            import app , myapp
from   myapp_tests_base import MyAppTestCase
import unittest

exec(open(app.root_path + '/constants/tests_constants.py').read())


class RootTestCase(MyAppTestCase):

  def test_unhandled_route_returns_404(self):
    resp = self.client.get('/unhandled/route')
    self.assertEqual(resp.status_code , NOTFOUND_STATUS)


  def test_web_root_renders_login(self):
    resp = self.client.get(ROOT_ROUTE)
    self.assertEqual(resp.status_code           , REDIRECT_STATUS        )
    self.assertRegex(resp.headers[RESP_URL_KEY] , r"" + LOGIN_ROUTE + "$")


  def test_login_logout(self):
    resp = self.login('ADMIN_LOGIN' ,  ADMIN_PASS )
    self.assertEqual(resp.status_code , SUCCESS_STATUS)
    self.assertIn   (LOGIN_ERROR_TEXT , resp.data     )
    resp = self.login( ADMIN_LOGIN  , 'ADMIN_PASS')
    self.assertEqual(resp.status_code , SUCCESS_STATUS)
    self.assertIn   (PASS_ERROR_TEXT  , resp.data     )
    resp = self.login( ADMIN_LOGIN  ,  ADMIN_PASS )
    self.assertEqual(resp.status_code , SUCCESS_STATUS)
    self.assertIn   (LOGIN_TEXT       , resp.data     )
    resp = self.logout()
    self.assertEqual(resp.status_code , SUCCESS_STATUS)
    self.assertIn   (LOGOUT_TEXT      , resp.data     )


if __name__ == '__main__':
  unittest.main()
